    /**
     * 1 页面被打开的时候  onShow
     *  1 获取url上的参数type
     *  2 根据type 去发送请获取订单数据
     *  3 渲染页面
     * 2 点击不同的标题重新发送请求获取和渲染数据
     */
    import { request } from "../../request/index.js";
    Page({

        /**
         * 页面的初始数据
         */
        data: {
            orders: [],
            tabs: [{
                    id: 0,
                    value: "全部订单",
                    isActive: true
                },
                {
                    id: 1,
                    value: "待付款",
                    isActive: false
                },
                {
                    id: 2,
                    value: "代发货",
                    isActive: false
                }, {
                    id: 3,
                    value: "退款/退货",
                    isActive: false
                },
            ],
            header: {}

        },
        onShow() {
            const token = wx.getStorageSync("token");
            if (!token) {
                wx.navigateTo({
                    url: '/pages/auth/auth',
                });
                return;
            }

            this.setData({
                    header: { Authorization: token },
                })
                /* 1.在onShow中无法拿到跳转连接中的参数options 
                    2. 只有在 onLoad中才能获取
                    3.只有从页面栈中获取链接中的参数
                    4.getCurrentPages(); 获取页面栈
                    5.
                */
                // console.log(options);
                // 1.获取小程序的页面栈-数组，长度最大是10个页面
            let pages = getCurrentPages();
            // 2. 获取索引最大的也买你就是当前页面 
            let currentPages = pages[pages.length - 1];
            //console.log(currentPages.options); // 链接中的参数
            const { type } = currentPages.options
                // 激活选中页面标题 -1的关系
            this.changeTitleByIndex(type - 1)
            this.getOrders(type, this.header)
                // this.getOrders(type)
                // token：Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo
        },
        // 获取订单列表的方法
        async getOrders(type, header) {
            let res = await request({ url: '/my/orders/all', data: { type }, header })
                // console.log(res);
            res = [{
                "order_id": 428,
                "user_id": 23,
                "order_number": "HMDD20190802000000000428",
                "order_price": 13999,
                "order_pay": "0",
                "is_send": "否",
                "trade_no": "",
                "order_fapiao_title": "个人",
                "order_fapiao_company": "",
                "order_fapiao_content": "",
                "consignee_addr": "广东省广州市海珠区新港中路397号",
                "pay_status": "1",
                "create_time": 1564731518,
                "update_time": 1564731518,
                "order_detail": null,
                "goods": [{
                    "id": 717,
                    "order_id": 428,
                    "goods_id": 43986,
                    "goods_price": 13999,
                    "goods_number": 1,
                    "goods_total_price": 13999,
                    "goods_name": "海信(Hisense)LED55MU9600X3DUC 55英寸 4K超高清量子点电视 ULED画质 VIDAA系统",
                    "goods_small_logo": "http://image5.suning.cn/uimg/b2c/newcatentries/0000000000-000000000160455569_1_400x400.jpg"
                }],
                "total_count": 1,
                "total_price": 13999
            }]
            let orders = res.map(v => ({...v, create_time_cn: (new Date(v.create_time * 1000).toLocaleString()) }));
            this.setData({
                // orders: res.orders,
                orders
            })
        },
        // 根据标题索引激活选中标题数组
        changeTitleByIndex(index) {
            // 2 修改原数组
            let { tabs } = this.data;
            tabs.forEach((v, i) => {
                i === index ? v.isActive = true : v.isActive = false;
            });
            //  赋值回到data中
            this.setData({
                tabs
            })
        },
        // 标题点击切换样式
        handletabsItemChange(e) {
            // 1 获取原数组标题索引
            const { index } = e.detail;
            // console.log(index);
            this.changeTitleByIndex(index)
                // 重新发送请求 type=1 index=0
            this.getOrders(index + 1, this.header)
        },


    })